//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    bannerMess:[],
    recommendMusic:[],
    unique:[],
    loadingbanner:false,
    loadingRecommend:false
  },
  //事件处理函数
  
  onLoad: function () {
    this.getBanner();
    this.getRecommendMusic();
    this.getUnique();
  },
  getBanner(){
    wx.request({
      url: app.globalData.Url+'/banner',
      success:res=>{
        if(res.data.banners.length>0){
          this.setData({
            bannerMess:res.data.banners,
            loadingbanner:true
          });
        }
      }
    })
  },
  getUnique(){
    wx.request({
      url: app.globalData.Url + '/personalized/privatecontent',
      success: res => {
        console.log(res);
        if (res.data.result.length > 0) {
          this.setData({
            unique: res.data.result
          });
        }
      }
    })
  },
  getRecommendMusic(){
    wx.request({
      url: app.globalData.Url + '/personalized',
      success: res => {
        let arr = res.data.result.filter(function(item){
          if (item.playCount>=10000){
            item.playCount = (item.playCount/10000).toFixed(2)+'万';
          }
          return true;
        });
        if (arr.length > 0) {
          this.setData({
            recommendMusic: arr,
            loadingRecommend: true
          });
        }
      }
    })
  }
})
